var express = require('express');
var axios = require('axios');
var router = express.Router();

router.get('/', function (req, res, next) {
    // let {studentId} = req.query
    console.log(req.session)
    // res.send("主页");
    var config = {
        method: 'get',
        baseURL: 'http://localhost:9023',
        url: '/student_work/getStudentTest',
        params: {
            studentId: req.session.userId
        },
    }
    axios(config)
        .then(function (response) {
            var newList = new Array();
            console.log(response.data);
            newList.push(response.data.data);
            newList.push(response.data.otherData);
            if (response.data.code == 0) {
                console.log("获取全部试卷信息成功");
                res.render('webPage/index', {
                    list: newList
                });
            } else {
                // console.log(response);
                res.render('webPage/notFound');
                // res.send({ err: -1, msg: "获取全部试卷信息失败" })
                console.log("获取全部试卷信息失败")
            }
        })
        .catch(function (error) {
            // console.log(error);
            res.render('webPage/notFound');
            // res.send({ err: -1, msg: "服务器错误，请刷新页面" })
            console.log("服务器错误")
        });
})


module.exports = router;
